package com.ihrm.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@Data
@NoArgsConstructor
public class Result<T> implements Serializable {

    private boolean success;//是否成功
    private Integer code;// 返回码
    private String message;//返回信息
    private Object data;// 返回数据

    public Result(Integer code,String message,boolean success) {
        this.code = code;
        this.message = message;
        this.success = success;
    }
    public Result(Integer code,String message,boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public static Result SUCCESS(){
        Result result =  new Result(Constants.SUCCESS_CODE, Constants.SUCCESS_MSG, true);
        return result;
    }

    public static <T> Result<T> SUCCESS(T data){
        Result<T> result =  new Result(Constants.SUCCESS_CODE, Constants.SUCCESS_MSG, true);
        result.setData(data);
        return result;
    }

    public static Result ERROR(){
        return new Result(Constants.SERVER_ERROR_CODE,Constants.SERVER_ERROR_MSG, false);
    }

    public static Result FAIL(){
        return new Result(Constants.FAIL_CODE,Constants.FAIL_MSG,false);
    }
}
